#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>
#include <dirent.h>

char fis[20][MAXPATHLEN];
char *pathname[MAXPATHLEN];

void cit_dir(int i)
{
	DIR *nume_dir;
	struct dirent *x;
	nume_dir = opendir (fis[i]);
	while ((x = readdir (nume_dir)) != NULL)
		if (strcmp (x->d_name, ".")== 0 || strcmp (x->d_name, "..") == 0);
		else
			fprintf (stdout, "%s\n", x->d_name);
}

void cmd_dir(char *comm)
{
	int ch;
	int i=1,j;
	char *c;
	c = strtok (comm, " ");
	while ((c = strtok (NULL, " ")) != NULL)
	{
		if (strcmp (c, "--help") == 0)
		{
			FILE *h = fopen ("help_dir.txt", "r");
			while ((ch = fgetc (h)) != EOF)
				fputc (ch, stdout);
			fclose (h);
			return;
		}
		else
		{
			strcpy (fis[i], c);
			i++;
		}
	}
	i--;
	if (i)
		for (j = 1; j <= i; j++)
			cit_dir (j);
	else
	{
		if (getwd(pathname) == NULL )
		{
			fprintf(stderr, "error\n");
			return;
		}
		else
		{
			fprintf (stderr, "pathname = %s\n", pathname);
			i = 1;
			strcpy (fis[i], pathname);
			cit_dir (i);
		}
	}
}

int main()
{
	char *comm;
        comm = readline ("usage: dir (folder)\ncommand: ");
	cmd_dir (comm);
	return 0;
}



